import React from 'react';

import './index.less';

import {base} from 'nc-lightapp-front';
import EmptyImg from '../../../../../hrpub/common/components/emptyImg';

const {NCMenu} = base;

const {NCSubMenu, Item} = NCMenu;

let buttonsShow = null;
export default class MainRowOperator extends React.Component{
    constructor(props) {
        super(props);
    }

    getButtonList(list) {
        let result = [];

        list.forEach((item) => {
            result.push(item.key);
            if(item.children) {
                result = result.concat(this.getButtonList(item.children));
            }
        });

        return result;
    }
    render() {
        const {
            language,
            isApprFlow,
            onClick,
            record,
            index,
            button,
            emp,
            close
        } = this.props;

        let billState = record.values['workflow_state'].value;

        if(buttonsShow === null) {
            let buttons = button.getButtons();
            buttonsShow = {};
            this.getButtonList(buttons).forEach((item) => {
                buttonsShow[item] = true;
            });
        }
        let billid = record.values.pk_entryapply.value
        return (
            <div 
                className="main-table-operator-btn"
                style={{
                    left: `${emp.rowsDetail.showX-17}px`,
                    top:`${emp.rowsDetail.showY-20}px`
                }}
                onMouseLeave = {close}
                ref={ref => this.opt = ref}
            >
                <NCMenu
                    mode="vertical"
                    className="main-table-operator-menu"
                    onClick={({item, key, keyPath}) => {
                        console.log(this.opt)
                        onClick(key, record, index);
                    }}
                    selectedKeys={[]}
                >
                    <If condition={billState === '0'}>
                            <If condition={buttonsShow['copy']}>
                                <Item
                                    key="copy"
                                >
                                    <a href="javascript:void(0)">
                                        {language['gx6008-000040']/** 复制 */}
                                    </a>
                                </Item>
                            </If>
                        </If>
                        <If condition={buttonsShow['approveinfo']}>
                            <Item
                                key="approveinfo"
                            >
                                <a href="javascript:void(0)">
                                    {language['gx6008-000041']/** 查看审批意见 */}
                                </a>
                            </Item>
                        </If>

                        
                        <If condition={billState === '-1'}>
                            <If condition={buttonsShow['edit']}>
                                <Item
                                    key="edit"
                                >
                                    <a href="javascript:void(0)">
                                        {language['gx6008-000038']/** 修改 */}
                                    </a>
                                </Item>
                            </If>
                            <If condition={buttonsShow['delete']}>
                                <Item
                                    key="delete"
                                >
                                    <a href="javascript:void(0)">
                                        {language['gx6008-000039']/** 删除 */}
                                    </a>
                                </Item>
                            </If>
                        </If>
                        <If condition={!['-1', '0', '2', '3', '102'].includes(billState) && isApprFlow[billid]}>
                            <If condition={buttonsShow['excute']}>
                                <Item
                                    key="excute"
                                >
                                    <a href="javascript:void(0)">
                                        {language['gx6008-000091']/** 执行 */}
                                    </a>
                                </Item>
                            </If>
                        </If>
                        <If condition={['1', '4', '5', '6'].includes(billState) && !isApprFlow[billid]}>
                            <If condition={buttonsShow['send_offer']}>
                                <Item
                                    key="send_offer"
                                >
                                    <a href="javascript:void(0)">
                                        {language['gx6008-000042']/** 发送offer */}
                                    </a>
                                </Item>
                            </If>
                            <If condition={buttonsShow['accept_offer']}>
                                <Item
                                    key="accept_offer"
                                >
                                    <a href="javascript:void(0)">
                                        {language['gx6008-000043']/** 接受offer */}
                                    </a>
                                </Item>
                            </If>
                            <If condition={buttonsShow['reject_offer']}>
                                <Item
                                    key="reject_offer"
                                >
                                    <a href="javascript:void(0)">
                                        {language['gx6008-000044']/** 拒绝offer */}
                                    </a>
                                </Item>
                            </If>
                        </If>
                        <If condition={['5', '6'].includes(billState) && !isApprFlow[billid]}>
                            <If condition={buttonsShow['submit_offer']}>
                                <Item
                                    key="submit_offer"
                                >
                                    <a href="javascript:void(0)">
                                        {language['gx6008-000045']/** 提交offer */}
                                    </a>
                                </Item>
                            </If> 
                        </If>
                        <If condition={buttonsShow['file']}>
                            <Item
                                key="file_manager"
                            >
                                <a href="javascript:void(0)">
                                    {language['gx6008-000071']/** 附件管理 */}
                                </a>
                            </Item>
                        </If>
                </NCMenu>
                {/* <div 
                    className="operator-mark-lay"
                    onClick={this.clickMark}
                ></div> */}
            </div>
        );
    }
}